<?php

namespace App\Http\Controllers\Api\Web\School;

use App\Http\Controllers\Common\GuardController;
use App\Models\Advert\Advert;
use App\Models\Article\ArticleInfo;
use App\Models\School\School;
use App\Service\SchoolService;
use Illuminate\Http\Request;

class SchoolController extends GuardController
{
    private $service;

    public function __construct() {
        $this->service = new SchoolService(School::class);
    }

    public function detail(Request $request) {
        $id = $request->input('id',0);
        $records = $this->service->detail($id);
        return responseSuccess($records->toArray());
    }

    public function getSchoolArticle(Request $request) {
        $id = $request->input('id',0);
        $records = ArticleInfo::where('school_id',$id)->where('status',1)->get();
        return responseSuccess($records->toArray(),$records->count());
    }
    public function getSchoolAdvert(Request $request) {
        $id = $request->input('id',0);
        $records = Advert::where('type',$id)->where('status',1)->get();
        return responseSuccess($records->toArray(),$records->count());
    }
}
